package com.bjpowernode.threadpool.submit;

import java.util.concurrent.*;

public class Test03 {

    public static void main(String[] args) throws Exception {
        ThreadFactory factory = (r) -> {
            Thread thread = Executors.defaultThreadFactory().newThread(r);
            thread.setUncaughtExceptionHandler( (t, e) -> {
                System.out.println(t.getName() + "--->" + e);
                e.printStackTrace();
            });
            return thread ;
        };

        //基于Executor框架实现线程池
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                8,
                16,
                15,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(1024),
                //Executors.defaultThreadFactory(),
                factory,
                //Executors.privilegedThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        threadPoolExecutor.execute(() -> {
            System.out.println("execute start......");
            int a = 10 / 0;
            System.out.println("execute end......");
        });

        threadPoolExecutor.shutdown();
    }
}
